<template>  
    <div id="body">
        <div class="top_head">
            <div class="fl">
                <div class="china_pingan">
                   <!--<img :src="imgurl" alt="">-->
                </div>
                <p class="p1" v-text="productName"></p>
                <p class="p2">保单号：<span v-text="policy_number"></span></p>
            </div>
            <div class="fr"></div>
        </div>
        <ul class="list">
            <li>
                <span class="head">保险责任</span>
            </li>
            <li class="itm" v-for="(item,index) in insured_liability" :class="{'itm_border':index==insured_liability.length-1}" >
                <span class="fl" v-text="item.name"></span>
                <span class="fr" v-text="item.content"></span>
            </li>
            <li class="itm_finally"></li>
                <li class="itm" v-for="(item,index) in insured_liabilit_finally" :class="{'itm_border':index==insured_liability.length-1}" >
                <span class="fl" v-text="item.name"></span>
                <span class="fr" v-text="item.content"></span>
            </li>
            <li>
                <span class="head">强制保险</span>
            </li>
            <li  class="itm" :class="{'itm_border':index==constraint.length-1}" v-for="(item,index) in constraint" >
                <span class="fl" v-text="item.name"></span>
                <span class="fr" v-text="item.content"></span>
            </li>
            <li class="itm_finally"></li>
            <li  class="itm" :class="{'itm_border':index==constraint_finally.length-1}" v-for="(item,index) in constraint_finally" >
                <span class="fl" v-text="item.name"></span>
                <span class="fr" v-text="item.content"></span>
            </li>
        </ul>
        <!--查看-->
        <div class="look">
                <p class="p1">
                查看
                <a href="javascript:;" class="a" @click="aa">《查看须知》</a>
                <a href="javascript:;" class="a">《保险条款》</a>
            </p>
            <p class="p2">
                <i class="iconfont ico">&#xe61c;</i>
                <span>本页面保单信息仅供参考，实际保单状态请以保险公司核心业务系统中记载为准</span>
            </p>
        </div>
        <!--最后-->
        <div class="bottom">
            <ul>
                <li class="fl l1">
                        <i class="iconfont ic">&#xe61a;</i>
                        <span>联系客服</span>
                </li>
                <li class="fl l2">
                        <i class="iconfont ic">&#xe610;</i>
                        <span>电子保单</span>
                </li>
                <li class="fl l3" v-on:click="say('dfs')">
                        <span>我要理赔</span>
                        <i class="iconfont ic">&#xe613;</i>
                </li>
            </ul>
        </div>


        <!--最外两个div-->
    </div>
</template>
<script>
// v-text="m.n" v-for="item in list" :class="{active:isTrue}"
// v-if="" v-else="" v-show=""
import Refresh from 'js/refresh.js'
import axios from 'axios'
import md5 from 'md5';
export default {
    data () {
        return {
            header: {
                title: '保单详情',
                back: '返回',
                close: '关闭'
            },
            imgurl: 'qqq', // img url
            policy_number: '43234343243dsad', // 保单号
            productName: '驾乘人员意外伤害保险（月）', // 产品名称
            insured_liability: [ // 保险责任
                // {name: '人身意外伤害-身故、残疾', content: '10万'},
                // {name: '意外医疗费（免赔额100元)', content: '50万'},
                // {name: '银行卡盗刷', content: '1万'}
            ],
            insured_liabilit_finally: [ // 保险责任下一个
                {name: '支持保费', content: '1元'},
                {name: '保障开始时间', content: '2016-12-10 00:00:00'},
                {name: '保障结束时间', content: '2016-12-10 23:59:59'}
            ],
            constraint: [ // 强制保险
                {name: '姓名', content: '1元'},
                {name: '证件类型', content: '2016-12-10 00:00:00'},
                {name: '证件号', content: '2016-12-10 23:59:59'},
                {name: '出生日期', content: '2016-12-10 23:59:59'},
                {name: '手机号', content: '2016-12-10 23:59:59'}
            ],
            constraint_finally: [
                    {name: '被保人', content: '本人'}
            ]
        }
    },
    created () {
    },
    mounted () {
        var _self = this;
        var oserid = '56';
        var odetailid = '1';
        var osign = md5('{"userid":oserid,"detailid":odetailid}md5_key');
        // console.log(osign)
        axios.post('http://192.168.32.95:8080/api/api.do', {
            'input': {
                'userid': oserid,  // 用户id
                'detailid': odetailid // 明细记录编号
               // 'tradeid': '20170112194801003' // 订单编号 // 为空则保单详情否则为订单详情
            },
            sign: osign, // 签名
            method: 'getTradeDetail'
        }, {
            headers: {
                height: 2392,
                width: 1440,
                osName: 'A',
                clientVersion: '1.0.0',
                clientType: 10,
                versionType: 2,
                deviceNo: '000000000000000',
                deviceName: 10,
                domainId: 100,
                'Content-Type': 'application/json',
                sessionId: '89f96da893e1851c260dbb45212ccd27'
            }
        })
        .then(function (response) {
            var output = response.data.output;
            console.log(response.data.output);
            _self.imgurl = output.insurerLogo // 产品logo
            _self.productName = output.productName; // 产品名称
            _self.policy_number = output.tradeId; // 保单号
            // 保险责任
            var list = response.data.output.typeList;
            // console.log(list)
            // console.log(list.length)
            var arr = [];
            for (let i = 0; i < list.length; i++) {
                arr.push(list[i].insureList)
            };
            var arr1 = [];
            for (let z = 0; z < arr.length; z++) {
                if (arr[z].length === 1) {
                    let nn = arr[z];
                    arr1.push(nn[0]);
                } else {
                    let nn = arr[z];
                    for (let zz = 0; zz < arr[z].length; zz++) {
                        arr1.push(nn[zz])
                    }
                }
            };
            var arr2 = [];
            for (let i = 0; i < arr1.length; i++) {
                arr2.push({name: arr1[i].insureName, content: arr1[i].insureAmount + arr1[i].amountUnit});
            };
            _self.insured_liability = arr2;
            _self.insured_liabilit_finally[0].content = parseFloat(output.payAmount) / 10 + '元'; // 支持保费
            // 保障开始时间
            var a = output.startTime;
            var b = a.substring(0, 4) + '-';
            var c = a.substring(4, 6) + '-';
            var d = a.substring(6, 8) + ' ';
            var e = a.substring(8, 10) + ':';
            var f = a.substring(10, 12) + ':';
            var g = a.substring(12, 14);
            _self.insured_liabilit_finally[1].content = b + c + d + e + f + g;
            // 保障结束时间
            var a1 = output.endTime;
            var b1 = a1.substring(0, 4) + '-';
            var c1 = a1.substring(4, 6) + '-';
            var d1 = a1.substring(6, 8) + ' ';
            var e1 = a1.substring(8, 10) + ':';
            var f1 = a1.substring(10, 12) + ':';
            var g1 = a1.substring(12, 14);
            // console.log(g1)
            _self.insured_liabilit_finally[2].content = b1 + c1 + d1 + e1 + f1 + g1;
           // 强制保险
            _self.constraint[0].content = output.applicant; // 强制保险-姓名
            _self.constraint[1].content = output.insuredList[0].idType; // 证件类型
            _self.constraint[2].content = output.insuredList[0].idTNo; // 证件号码
           // _self.insured_liability.push({name: '支持保费', content: '1元'});
            // 出生日期
            var a11 = output.insuredList[0].birthday;
            var b11 = a11.substring(0, 4) + '-';
            var c11 = a11.substring(4, 6) + '-';
            var d11 = a11.substring(6, 8) + ' ';
            _self.constraint[3].content = b11 + c11 + d11;
            _self.constraint[4].content = output.insuredList[0].mobile; // 手机号
            _self.constraint_finally[0].content = output.insuredList[0].insuredName; // 被保人
        })
        .catch(function (error) {
            console.log(error);
        });
    },
    computed: {
    },
    methods: {
        ab () {
            console.log('a')
        },
        aa () {
            this.policy_number.title === 2;
        }
    }
}
</script>
